package com.anysoft.guide;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.anysoft.R;
import com.anysoft.base.BaseActivity;
import com.anysoft.home.HomeActivity;
import com.rd.PageIndicatorView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wwq on 2016/12/5.
 */

public class GuideNewActivity extends BaseActivity {
    private ViewPager viewPager;
    private PageIndicatorView pageIndicatorView;
    private Button btn;

    private List<View> pageList = new ArrayList<>();
    private HomeGuideAdapter adapter;

    private Animation showAnim = null;
    private Animation hideAnim = null;
    private boolean isIndicatorShow = true;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.guide_activity);

        showAnim = AnimationUtils.loadAnimation(this, R.anim.view_alpha_show);
        hideAnim = AnimationUtils.loadAnimation(this, R.anim.view_alpha_hide);

        viewPager = (ViewPager) findViewById(R.id.viewPager);
        pageIndicatorView = (PageIndicatorView) findViewById(R.id.pageIndicatorView);
        btn = (Button) findViewById(R.id.btn);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent().setClass(GuideNewActivity.this, HomeActivity.class));
                finish();
            }
        });

        initData();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    private void initData() {
        adapter = new HomeGuideAdapter();
        pageList.addAll(createPageList());

        adapter.setData(pageList);
        viewPager.setAdapter(adapter);

        pageIndicatorView.setViewPager(viewPager);
    }

    private List<View> createPageList() {
        List<View> pageList = new ArrayList<>();
        pageList.add(createPageView(R.mipmap.p1_750_750, "XXXXXX，12年，1.2万亿", "理财新征程", false));
        pageList.add(createPageView(R.mipmap.p5_750_750, "现金快线", "闲钱理财 优惠购基", false));
        pageList.add(createPageView(R.mipmap.p3_750_750, "指纹登录", "财富 触手可及", false));
        pageList.add(createPageView(R.mipmap.p4_750_750, "工银现金快线3.0", "全新体验 更懂你", true));

        return pageList;
    }

    private View guideView;
    private ImageView iv_item_guide;
    private TextView tv_item_guide_gray;
    private TextView tv_item_guide_red;
    private Button btn_item_guide;

    @NonNull
    private View createPageView(int bg, String title1, String title2, boolean isBtnShow) {

        guideView = View.inflate(mActivity, R.layout.item_guide, null);
        iv_item_guide = (ImageView) guideView.findViewById(R.id.iv_item_guide);
        tv_item_guide_gray = (TextView) guideView.findViewById(R.id.tv_item_guide_gray);
        tv_item_guide_red = (TextView) guideView.findViewById(R.id.tv_item_guide_red);
        btn_item_guide = (Button) guideView.findViewById(R.id.btn_item_guide);

        iv_item_guide.setBackgroundDrawable(getResources().getDrawable(bg));
        tv_item_guide_gray.setText(title1);
        tv_item_guide_red.setText(title2);
        if (isBtnShow) {
            btn_item_guide.setVisibility(View.VISIBLE);

            btn_item_guide.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    startActivity(new Intent().setClass(GuideNewActivity.this, HomeActivity.class));
                    finish();
                }
            });
        }

        View view = new View(this);
        view.setBackgroundDrawable(getResources().getDrawable(bg));

        return guideView;
    }
}
